﻿using System;
using System.Diagnostics.CodeAnalysis;
using JTLeigh.Commerce.Spencer.Core.Common;

namespace JTLeigh.Commerce.Spencer.Features.ProductFeedback.Common.Entities
{

	/// <summary>
	/// Wraps a product review attribute, an optional localization, and an optional association, 
	/// and exposes properties from these objects with fallback when the objects are <see langword="null"/>.
	/// </summary>
	[SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix", Justification = "Reviewed.")]
	public class LocalizedProductReviewAttribute
	{

		#region Fields

		private ProductReviewAttribute _attribute;
		private ProductReviewAttributeLocalization _localization;
		private ProductReviewAttributeAssociationBase _association;

		#endregion // Fields

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="LocalizedProductReviewAttribute"/> class 
		/// with the specified attribute, localization, and association.
		/// </summary>
		/// <param name="attribute">The <see cref="ProductReviewAttribute"/> to wrap.</param>
		/// <param name="localization">The <see cref="ProductReviewAttributeLocalization"/> to 
		/// wrap, or <see langword="null"/> if no localization was found.</param>
		/// <param name="association">The <see cref="ProductReviewAttributeAssociationBase"/> to
		/// wrap, or <see langword="null"/> if no association was found.</param>
		public LocalizedProductReviewAttribute(ProductReviewAttribute attribute, ProductReviewAttributeLocalization localization, ProductReviewAttributeAssociationBase association)
		{
			Safety.AssertArgumentNotNull("attribute", attribute);
			// localization can be null
			// association can be null

			_attribute = attribute;
			_localization = localization;
			_association = association;
		}

		#endregion // Constructors

		#region Properties

		/// <summary>
		/// Gets the attribute identifier.
		/// </summary>
		/// <value>An attribute identifier <see cref="Guid"/>.</value>
		public Guid AttributeId
		{
			get { return _attribute.AttributeId; }
		}

		/// <summary>
		/// Gets the attribute text.
		/// </summary>
		/// <value>If a localization was provided, the localization's text.  Otherwise, the 
		/// attribute's default text.</value>
		public string Text
		{
			get
			{
				return (_localization != null) ? _localization.Text : _attribute.DefaultText;
			}
		}

		/// <summary>
		/// Gets the attribute display order.
		/// </summary>
		/// <value>If an association was provided, the association's display order.  Otherwise, 
		/// <c>0</c>.</value>
		public int DisplayOrder
		{
			get
			{
				return (_association != null) ? _association.DisplayOrder : 0;
			}
		}

		#endregion // Properties

	}

}
